import '@/assets/main.css'
import '@/assets/reset.css'
import 'nprogress/nprogress.css'
import 'ant-design-vue/dist/reset.css'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import App from './App.vue'
import AppLoading from './components/AppLoading.vue'
import router from './router'
import { registerGlobComp } from '@/utils'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'

function setupApp() {
  dayjs.locale('zh-cn')
  const appLoading = createApp(AppLoading)
  appLoading.mount('#appLoading')
  const app = createApp(App)
  const pinia = createPinia()
  pinia.use(piniaPluginPersistedstate)
  registerGlobComp(app)
  app.use(router)
  app.use(pinia)
  // 全局监听错误
  app.config.errorHandler = (err, vm, info) => {
    console.error(err)
    console.error(vm)
    console.error(info)
  }
  // 全局监听警告
  app.config.warnHandler = (msg, vm, info) => {
    console.warn(msg)
    console.warn(vm)
    console.warn(info)
  }
  const appLoadingTimeout = 300
  setTimeout(() => {
    app.mount('#app')
  }, appLoadingTimeout)
}
setupApp()
